package com.jinrustar.httpfileserver.springboot.controller;

import com.jinrustar.httpfileserver.core.base.BaseController;
import com.jinrustar.httpfileserver.core.support.Assert;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@Api(value = "", description = "")
@RequestMapping(value = "/", method = {RequestMethod.GET, RequestMethod.POST})
public class LoginController extends BaseController {

    @RequestMapping(value = "/login")
    @ResponseBody
    public Object login(ModelMap modelMap, HttpServletRequest request, HttpSession httpSession,
                        @RequestParam(value = "account", required = false) String account) {
        Assert.notNull(account);
        if (account.equals("admin")) {
            httpSession.setAttribute("account", account);
        }

        return httpSession.getAttribute("account");
    }
}
